<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="libs/js/jquery-2.1.1.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="libs/carhartl-jquery-cookie-v1.4.1-0-g7f88a4e/carhartl-jquery-cookie-92b7715/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
		<link rel="stylesheet" type="text/css" href="libs/css/login.css"/>
	</head>
	<body>
		<div id="head">
			
		</div>
		<div id="content">
			<table >
				<tr><td>手机/邮箱：</td><td><input type="text" id="phone" name="" style="border: 1px solid black;"/></td></tr>
				<tr><td>密码：</td><td><input type="password" name="" id="username" value="" style="border: 1px solid black;"/></td></tr>
				<tr><td></td><td><input type="checkbox" name="" id="" value="" />下次自动登录</td></tr>
				<tr><td></td><td>忘了密码？<a href="#"  style="color: red;">注册</a></td></tr>
				<tr><td></td><td><button>登录</button></td></tr>
			</table>
		</div>
		<div id="foot">
			
		</div>
		<script type="text/javascript">
			$('#head').load('head.html?_='+Math.random());
			$('#foot').load("footer.html?_="+Math.random());
			var n=0;
			$('button').click(function(){
				//跟注册差不多首先比对用户名是否一存在cookie中用for循环的方法
				//找到用户名之后 再比对输入的密码 如果一致则登录成功
				//如果前面正确的话这里取到的应该是一个"{name:122,pass:123},{name:..,pass:...}"
				var str0 = $('input[type=text]').val();
				var str1 = $('input[type=password]').val();
				var arr=[];
				var getInfo = JSON.parse($.cookie('userInfo'));
				
				for(var i = 0; i < getInfo.length; i++){
					if(getInfo[i].name == str0){
						if(getInfo[i].pass == str1){
							
							n=1;
							break;
						}
					}
				}
				if(n==1){
					console.log('登陆成功');
					alert("登录成功");
					window.location.href="homePage.html";
					n=0;
				}else{
					alert("登录失败");
					window.location.reload();
					console.log('登录失败');
				}
				//console.log(typeof(getInfo[0].pass));
				
			});
			
		</script>
	</body>
</html>
